package com.formula.datastructure.exercise.queue;

/**
 * 顺序队列不需要单独节点
 */
public class SeqQueue {
    // 不考虑扩容
    int SIZE = 50;
    Integer[] array = new Integer[SIZE];

    // front用于deq, rear用于enq
    private int front;
    private int rear;

    public boolean isEmpty() {
        return front == rear;
    }

    public boolean isFull() {
        return (rear + 1) % SIZE == front;
    }

    public int enQueue(Integer data) {
        if (!isFull()) {
            rear = (rear + 1) % SIZE;
            array[rear] = data;
            return 1;
        }
        return 0;
    }

    public Integer deQueue() {
        if (!isEmpty()) {
            front = (front + 1) % SIZE;
            return array[front];
        }
        return null;
    }


    public static void main(String[] args) {

    }
}
